package indexPack;

import java.io.File;
import java.io.IOException;

import org.apache.lucene.analysis.Analyzer;

import tools.Filtro;
import directoryPath.DirectoryController;


public class IndexManager {

private IndexController index;
private DirectoryController indexDir;
private DirectoryController dataDir;
private String Extension;
private Analyzer analyzer;

public IndexManager(DirectoryController indexDir,DirectoryController dataDir,Analyzer analyzer,String Extension){
	this.indexDir = indexDir;
	this.dataDir = dataDir;
	this.analyzer = analyzer;
	this.Extension = Extension;
}

public void addDocuments(boolean exists) throws IOException{
	
	//true -> crea el index, false -> solo lo abre
	index = new IndexController(indexDir.getFile(),dataDir.getFile(),analyzer,exists);
	File[] files = dataDir.getListFiles();
	Filtro f = new Filtro();
	f.setExtension(Extension);
	
	for(File file : files){
		if (f.accept(file))
		    index.doIndexFile(index.getIndex(), file);
	}	
	index.optimizar();
	index.cerrar();
}

}
